package com.quanyan.order.service;

import com.quanyan.api.APIRequest;
import com.quanyan.api.APIResponse;
import com.quanyan.api.enums.ApiResponseEnum;
import com.quanyan.order.entity.Order;
import com.quanyan.order.entity.OrderExample;
import com.quanyan.order.entity.OrderRefund;
import com.quanyan.order.enums.OrderStatusEnum;
import com.quanyan.orderpay.request.*;
import com.quanyan.orderpay.response.mq.RefundNotifyMsg;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @author songzj
 * @date 16/6/6-15:19
 */
public interface OrderService {
    Byte PAY_STATE_UN_PAYED = 0; //
    Byte PAY_STATE_PAYED = 1;
    Byte PAY_STATE_REFUNDING = 2;
    Byte PAY_STATE_REFUND = 3;


    Byte ORDER_REFUND_STATUS_NO = 0;
    Byte ORDER_REFUND_STATUS_YES = 1;
    Byte ORDER_REFUND_STATUS_FAIL = 2;


    /**
     * 新增订单主体
     *
     * @param orderSaveApiRequest
     * @return
     */
    Order insertOrderEntity(APIRequest<ReqOrderSave> orderSaveApiRequest);

    /**
     * 订单支付成功
     *
     * @param orderNo
     * @param payId
     * @param payName
     * @param payTime
     * @return
     */
    int updateOrderPaySuccess(String orderNo, Integer payId, String payName, Date payTime);


    /**
     * 校验订单合法性.
     * 校验订单退款数量/金额合法性
     *
     * @param reqOrderRefund
     * @param refundOrderNo
     *@param totalRefundRmbAmount @return
     */
    APIResponse<OrderRefund> refundApply(ReqOrderRefund reqOrderRefund, String refundOrderNo, BigDecimal totalRefundRmbAmount);


    /**
     * 审核退款申请
     * @param reqAuditEntity
     * @return
     */
    APIResponse<ApiResponseEnum> auditRefundApply(ReqAuditEntity reqAuditEntity);

    /**
     * 获取订单号
     * @param orderId
     * @param orderNo
     * @return
     */
    Order selectOrderByOrderNo(Integer orderId, String orderNo);

    /**
     * 取消订单
     * @param data
     * @return
     */
    boolean cancelOrder(ReqOrderCancel data);

    /**
     * 关闭订单
     * @param orderId
     * @return
     */
    boolean closeOrder(int orderId);

    /**
     * 更新订单状态
     * @param orderId
     * @param orderStatusEnum
     * @return
     */
    boolean updateOrderStatus(int orderId, OrderStatusEnum orderStatusEnum);


    boolean refundComplateProcess(RefundNotifyMsg refundNotifyMsg);

    APIResponse refundCompleteProcess(String refundOrderNo, String result);

    List<ReqRefundProduct> selectOrderProductByOrderNo(Integer orderId);

    Order selectByOrderInfo(ReqOrderInfo reqOrderInfo);

    List<Order> selectByExample(OrderExample orderExample);

    void updateOrderPayId(String orderNo, Integer payId);
}
